﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yugi.Client.Card;
namespace Yugi.Client
{
    public class PlayerModel : BaseModel
    {
        public Player YPlayer { get; set; }
      
        public List<CardModel> YListCard { get; set; }
        public List<CardModel> YBaiTrenBan { get; set; }
        public List<CardModel> YDeck { get; set; }
        public IInvoke Health_Presenter { get; set; }
        public IInvoke Presenter { get; set; }
        public IInvoke Deck_Presenter { get; set; }
        public SupervisorModel YSupervisorModel { get; set; }
        private EnumTable state_now;
        public EnumTable YStateNow 
        {
            get
            {
                return state_now;
            }
            set
            {
                state_now = value;
                this.OnChange("YStateNow");
            }

        }
       
        public PlayerModel()
        {
            YListCard = new List<CardModel>();
            YBaiTrenBan = new List<CardModel>();
            YDeck = new List<CardModel>();
        }
        public void ReciveMessageFromView(ClientMSG Message, params object[] param)
        {
            switch (Message)
            {
                case ClientMSG.ChonBaiXong:
                    YSupervisorModel.SendMessageToServer(Common.YMSG.CARD_LENBAI, param);
                    break;
                case ClientMSG.LenBaiSpell:
                    //YSupervisorModel.TableGame.ReceiveMessageFromSupervisor(ClientMSG.LenBaiSpell, param);
                    YSupervisorModel.SendMessageToServer(Common.YMSG.CARD_LENBAI_SPELL, param);
                    break;
                case ClientMSG.LenBaiTrap:
                    YSupervisorModel.SendMessageToServer(Common.YMSG.CARD_LENBAI_TRAP, param);
                    break;
                case ClientMSG.LenBaiDacBiet:
                    YSupervisorModel.TableGame.ReceiveMessageFromSupervisor(ClientMSG.LenBaiDacBiet, param);
                    break;
            }
        }
        public void ReceiveMessageFromSupervisor(ClientMSG Message, params object[] param)
        {
            switch (Message)
            {
                
                case ClientMSG.DoiDiem:
                    Health_Presenter.Do(Message, param);
                    break;
                default:
                    Presenter.Do(Message, param);
                    break;
            }
        }
        public YBaseCard FindOnTable(int id)
        {
            return (this.YBaiTrenBan.Find(p => p.YCard.ID == id)).YCard;
        }
        public CardModel FindOnTableAsCardModel(int id)
        {
            return (this.YBaiTrenBan.Find(p => p.YCard.ID == id));
        }
        public YBaseCard Find(int id)
        {
            return (YListCard.Find(p => p.YCard.ID == id)).YCard;
        }
        public CardModel FindAsCardModel(int id)
        {
            return (YListCard.Find(p => p.YCard.ID == id));
        }
        public bool BiTanCongTrucTiep()
        {
            foreach (var item in YBaiTrenBan)
            {
                if (item.YCard.CardType == YType.Monster)
                    return false;
            }
            return true;
        }
        
        public void Reset()
        {
            this.YBaiTrenBan.Clear();
            this.YListCard.Clear();
            this.YDeck.Clear();
        }
    }
}
